package com.tuiyun.jxgl.action;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.transaction.annotation.Transactional;

import com.tuiyun.jxgl.bean.Driver;
import com.tuiyun.jxgl.dao.DriverHome;
import com.tuiyun.jxgl.dao.StudentHome;
import com.tuiyun.util.PWDUtil;

public class NewDriverAction {	
	
	private String msg;
	@Transactional
	public String execute(){
		if(sh.findByUsername(getUsername()) != null || dh.findByUsername(getUsername()) != null){
			msg = "用户名已经存在！";
			return "error";
		}
		Driver d = new Driver();
		d.setAddress(address);
		d.setAge(age);
		d.setCarCode(carCode);
		d.setDriverType(driverType);
		d.setGender(gender);
		d.setIdcard(idCard);
		d.setLicenseCode(licenseCode);
		d.setLicenseType(licenseType);
		d.setLiveCity(liveCity);
		d.setName(username);
		d.setPhone(phone);
		//d.setProfileid(profileid)
		d.setPwd(PWDUtil.encryptPWD(pwd));
		d.setRate((byte) 5);
		d.setRealName(realName);
		d.setVcode(vcode);
		dh.persist(d);
		msg = "添加成功！";
		return "success";
	}
	
	private DriverHome dh;
	private StudentHome sh;
	
	public StudentHome getSh() {
		return sh;
	}
	public void setSh(StudentHome sh) {
		this.sh = sh;
	}

	private int age;
	private byte gender;
	private byte driverType;
	public byte getDriverType() {
		return driverType;
	}
	public void setDriverType(byte driverType) {
		this.driverType = driverType;
	}

	private String pwd;
	private String username;
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	public DriverHome getDh() {
		return dh;
	}
	public void setDh(DriverHome dh) {
		this.dh = dh;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	public byte getGender() {
		return gender;
	}
	public void setGender(byte gender) {
		this.gender = gender;
	}
	public String getPwd() {
		return pwd;
	}
	public void setPwd(String pwd) {
		this.pwd = pwd;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public String getRealName() {
		return realName;
	}
	public void setRealName(String realName) {
		this.realName = realName;
	}
	public String getIdCard() {
		return idCard;
	}
	public void setIdCard(String idCard) {
		this.idCard = idCard;
	}
	public String getVcode() {
		return vcode;
	}
	public void setVcode(String vcode) {
		this.vcode = vcode;
	}
	public String getLicenseCode() {
		return licenseCode;
	}
	public void setLicenseCode(String licenseCode) {
		this.licenseCode = licenseCode;
	}
	public String getCarCode() {
		return carCode;
	}
	public void setCarCode(String carCode) {
		this.carCode = carCode;
	}
	public String getLiveCity() {
		return liveCity;
	}
	public void setLiveCity(String liveCity) {
		this.liveCity = liveCity;
	}

	private String phone;
	private String address;
	private String realName;
	private String idCard;
	private String vcode;
	private String licenseCode;
	private String licenseType;
	public String getLicenseType() {
		return licenseType;
	}
	public void setLicenseType(String licenseType) {
		this.licenseType = licenseType;
	}

	private String carCode;
	private String liveCity;
}
